using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SiteManager;
using System.Data.SqlClient;


/// <summary>
/// Summary description for Dentist
/// </summary>
public class Dentist
{
    Manager objManager = new Manager(true,"ConnectionString");
    private int iUserId = 0;
    private int iDentistId = 0;
    private int iFeatureDentistTypeId=0;
    private int iSpecialityId=0;

    private int iSubSpecialityId = 0; 
    
    private string sTransactionId = "";
    private string sTransactionDate = "";
    private string sTransactionAmount = "";
    private string sSubscriptionId = "";
    //private string sExpYear = "";
    //private string sExpMonth = "";
    //private string sCardNumber = "";
    private string sSubscriptionType = "";
    private string sPhoto = "";
    private string swebsite = "";
    private string sprof_desc = "";
    private bool isCheck = false;
    private byte[] myimage;
    private byte[] th_Dentistimage;
    
    public Dentist()
	{
		//
		// TODO: Add constructor logic here
		//
	}
#region Property
   /// <summary>
   /// Public Property 
   /// </summary>
   /// 
    public bool IsCheck
    {
        get { return isCheck; }
        set { isCheck = value; }

    }
    public int UserId
    {
        get { return iUserId; }
        set { iUserId = value; }

    }
    public int DentistId
    {
        get { return iDentistId; }
        set { iDentistId = value; }

    }
    public string TransactionId
    {
        get { return sTransactionId; }
        set { sTransactionId = value; }

    }
    public string  TransactionDate
    {
        get { return sTransactionDate; }
        set { sTransactionDate = value; }

    }
    public string TransactionAmount
    {
        get { return sTransactionAmount; }
        set { sTransactionAmount = value; }

    }

    public string SubscriptionId
    {
        get { return sSubscriptionId; }
        set { sSubscriptionId = value; }

    }
    public string SubscriptionType
    {
        get { return sSubscriptionType; }
        set { sSubscriptionType = value; }

    }
      public int FeatureDentistTypeId
    {
        get { return iFeatureDentistTypeId; }
        set { iFeatureDentistTypeId = value; }

    }
      public int SpecialityId 
    {
        get { return iSpecialityId; }
        set { iSpecialityId = value; }

    }

    public int SubSpecialityId
    {
        get { return iSubSpecialityId; }
        set { iSubSpecialityId = value; }

    }

    public byte[] image
    {
        get { return myimage; }
        set { myimage = value; }

    }

    public byte[] th_image
    {
        get { return th_Dentistimage; }
        set { th_Dentistimage = value; }

    }

    // public string CardNumber
    //{
    //    get { return sCardNumber; }
    //    set { sCardNumber = value; }

    //}
    // public string ExpMonth
    //{
    //    get { return sExpMonth; }
    //    set { sExpMonth = value; }

    //}
    // public string ExpYear
    //{
    //    get { return sExpYear; }
    //    set { sExpYear = value; }

    //}
    private int iUserType = 0;
    private int iLoginID = 0;
    private string sCouponCode = "";
    public int UserType
    {
        get { return iUserType; }
        set { iUserType = value; }

    }
    public int LoginID
    {
        get { return iLoginID; }
        set { iLoginID = value; }

    }
    public string CouponCode
    {
        get { return sCouponCode; }
        set { sCouponCode = value; }

    }
    public string photo
    {
        get { return sPhoto; }
        set { sPhoto = value; }
    }
    public string website
    {
        get { return swebsite; }
        set { swebsite = value; }
    }
    public string prof_desc
    {
        get { return sprof_desc; }
        set { sprof_desc = value; }
    }
     
	

#endregion

    /// <summary>
    /// Authenticate the credentials provided for a Dentist login
    /// Author: 
    /// Implemented By: Wahaj
    /// </summary>
    /// <param name="email">Email of Dentist</param>
    /// <param name="pass">Password</param>
    /// <param name="extraPath">extraPath is obsolete in current scenario, pass 'Dentist/' or empty string</param>
    /// <returns>Error message if login False, else redirects to the Dentist content page</returns>
    /// <remarks>
    /// Following session varibles are set on authentication:
    /// userID, LoginName, UserEmail
    /// userType = "Dentist"
    /// DentistType = "Dentist"
    /// </remarks>
    public string DoLogin(string email, string pass, string extraPath)
    {
        if (email.Trim().Length == 0 || pass.Length == 0)
        {
            return "Invalid Login";
        }

        objManager = new Manager(true,"ConnectionString");
        string strSql = "select id,upin,fname,lname,password from tbl_Dentists where email='" + objManager.FixQuote(email) + "' and isdelete=0";
        SqlDataReader sqlDr = objManager.ExecuteQuery(strSql);
        if (sqlDr.Read())
        {
            if (string.Compare(sqlDr["password"].ToString(), pass, false) == 0)
            {
                HttpContext.Current.Session["userID"] = sqlDr["id"].ToString();
                HttpContext.Current.Session["userType"] = "Dentist";
                HttpContext.Current.Session["LoginName"] = sqlDr["fname"].ToString() + " " + sqlDr["lname"].ToString();
                HttpContext.Current.Session["UserEmail"] = email;
                
                // NEW SESSION VARIBLE ADDED 
                // DATE 15TH FEB 2008
                HttpContext.Current.Session["DoctorType"] = "Dentist"; 
                
                sqlDr.Close();
                
                if (!string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["fromPg"]))
                    HttpContext.Current.Response.Redirect(HttpContext.Current.Request.QueryString["fromPg"]);
                else
                    if (extraPath != "NOREDIRECT")
                    {
                        localFunction obj = new localFunction();
                        obj.GetDrInfo(true);
                        //HttpContext.Current.Response.Redirect(HttpContext.Current.Session["strHttp"].ToString() + "Dentist/DentistContent.aspx");
                    }   //HttpContext.Current.Response.Redirect(extraPath + "DentistContent.aspx");
            }
            else
            {
                sqlDr.Close();
                HttpContext.Current.Session["ShowLayer"] = "True";
                return "Your password is incorrect. Please try again.";
            }
        }
        else
        {
            sqlDr.Close();
            HttpContext.Current.Session["ShowLayer"] = "True"; 
            return "Your login information is incorrect. Please try again.";
        }
        return "";
    }

    public int addtomyDentists()
    {
        int iresult = 0;
        try
        {
            SqlParameter[] sqlparam = new SqlParameter[4];
            sqlparam[0] = new SqlParameter("@SNO",SqlDbType.BigInt);
            sqlparam[0].Value = 0;
            sqlparam[1] = new SqlParameter("@UserID ", iUserId);
            sqlparam[2] = new SqlParameter("@DentistId", iDentistId);
            sqlparam[3] = new SqlParameter("@Result", SqlDbType.BigInt);
            sqlparam[3].Direction = ParameterDirection.Output;
            objManager.ExecuteUpdate("[AddToMyDentist]", sqlparam);
            return Convert.ToInt32(sqlparam[3].Value);
            
        }
        catch(Exception ex)
        {
            HttpContext.Current.Response.Write(ex.Message.ToString());
           
        }
        return iresult;
    }
    public System.Data.DataSet GetMyDentistByUserId(int Userid)
    {
       
        SqlParameter[] _SqlparameterObject = null;

        try
        {
            _SqlparameterObject = new SqlParameter[1];
            _SqlparameterObject[0] = new SqlParameter("@UserId", Userid);
            DataSet ds = objManager.ExecuteQuery("[GetMyDentistByUserId]", _SqlparameterObject, "tblMyDentist");

            return ds   ;
        }
        catch (Exception ex)
        {
         
            throw (ex);
        }
        finally
        {
           
            _SqlparameterObject = null;
        }
    }
    public System.Data.DataSet GetMyRatingDentistByUserId(int Userid)
    {

        SqlParameter[] _SqlparameterObject = null;

        try
        {
            _SqlparameterObject = new SqlParameter[1];
            _SqlparameterObject[0] = new SqlParameter("@UserId", Userid);
            DataSet ds = objManager.ExecuteQuery("[GetMyRatingDenByUserId]", _SqlparameterObject, "tblMyDentist");

            return ds;
        }
        catch (Exception ex)
        {

            throw (ex);
        }
        finally
        {

            _SqlparameterObject = null;
        }
    }
    public bool  CheckCouponCode()
    {
        bool iresult = false;
        try
        {
            SqlParameter[] sqlparam = new SqlParameter[4];
            sqlparam[0] = new SqlParameter("@CouponCode", sCouponCode);
            sqlparam[1] = new SqlParameter("@Type ", iUserType);
            sqlparam[2] = new SqlParameter("@ID", iLoginID);
            sqlparam[3] = new SqlParameter("@IsExist", SqlDbType.Bit);
            sqlparam[3].Direction = ParameterDirection.Output;
            objManager.ExecuteUpdate("[CheckCouponCode]", sqlparam);
            return Convert.ToBoolean(sqlparam[3].Value);

        }
        catch (Exception ex)
        {
            HttpContext.Current.Response.Write(ex.Message.ToString());

        }
        return iresult;
    }



    public int InsertDentistSubscription()
    {
        int iresult = 0;
        try
        {
            SqlParameter[] sqlparam = new SqlParameter[15];
            sqlparam[0] = new SqlParameter("@Id", SqlDbType.BigInt);
            sqlparam[0].Value = 0;
            sqlparam[1] = new SqlParameter("@DentistId ", iDentistId);
            sqlparam[2] = new SqlParameter("@TransactionId", sTransactionId);
            sqlparam[3] = new SqlParameter("@TransactionDate", sTransactionDate);
            sqlparam[4] = new SqlParameter("@TransactionAmount", sTransactionAmount);
            sqlparam[5] = new SqlParameter("@SubscriptionId", sSubscriptionId);
            sqlparam[6] = new SqlParameter("@SubscriptionType", sSubscriptionType);
            sqlparam[7] = new SqlParameter("@FeaturedocTypeId", iFeatureDentistTypeId);
            sqlparam[8] = new SqlParameter("@SpecialityId",iSpecialityId);
            sqlparam[9] = new SqlParameter("@photo", sPhoto);
            sqlparam[10] = new SqlParameter("@website", swebsite);
            sqlparam[11] = new SqlParameter("@prof_desc",sprof_desc);
            //sqlparam[9] = new SqlParameter("@CardNumber", sCardNumber);
            //sqlparam[10] = new SqlParameter("@ExpMonth", sExpMonth);
            //sqlparam[11] = new SqlParameter("@ExpYear", sExpYear);
            sqlparam[12] = new SqlParameter("@Result", SqlDbType.BigInt);
            sqlparam[12].Direction = ParameterDirection.Output;

            sqlparam[13] = new SqlParameter("@SubSpecialityId", iSubSpecialityId);
            sqlparam[14] = new SqlParameter("@isCheck", isCheck);
            
            //sqlparam[14] = new SqlParameter("@Image", myimage);
            //sqlparam[15] = new SqlParameter("@th_Image", th_Dentistimage);

            objManager.ExecuteUpdate("[InsertDentistSubscription]", sqlparam);
            return Convert.ToInt32(sqlparam[12].Value);

        }
        catch (Exception ex)
        {
            HttpContext.Current.Response.Write(ex.Message.ToString());

        }
        return iresult;
    }

    public int UpdateDentistSubscription()
    {
        int iresult = 0;
        try
        {
            SqlParameter[] sqlparam = new SqlParameter[6];
            sqlparam[0] = new SqlParameter("@DentistId ", iDentistId);
            sqlparam[1] = new SqlParameter("@photo", sPhoto);
            sqlparam[2] = new SqlParameter("@website", swebsite);
            sqlparam[3] = new SqlParameter("@prof_desc", sprof_desc);
            sqlparam[4] = new SqlParameter("@Result", SqlDbType.BigInt);
            sqlparam[5] = new SqlParameter("@isCheck", isCheck);
            
            sqlparam[4].Direction = ParameterDirection.Output;

            //Commented at 05/03/2008 by ranjeet to save image into File

            //sqlparam[5] = new SqlParameter("@Image", myimage);
            //sqlparam[6] = new SqlParameter("@th_Image", th_Dentistimage);

            //Commented End

            objManager.ExecuteUpdate("[UpdateDentistSubscription]", sqlparam);
            return Convert.ToInt32(sqlparam[4].Value);

        }
        catch (Exception ex)
        {
            HttpContext.Current.Response.Write(ex.Message.ToString());

        }
        return iresult;
    }
    public void DeleteDentistSubscription(int pDentistID)
    {
        Manager objManager = new Manager(true,"ConnectionString");
        SqlParameter[] objSqlParameter = new SqlParameter[1];
        objSqlParameter[0] = new SqlParameter("@DentistID", SqlDbType.BigInt);
        objSqlParameter[0].Value = pDentistID;
        objManager.ExecuteQuery("DeleteDentistSubscription", objSqlParameter);
        
    }

    /// <summary>
    ///  This function is use for delete a Dentist from
    ///  my Dentist list 
    /// </summary>
    /// <author>Vinayak Singh Rathore</author>
    /// <date>29 Sep, 2007</date>
    /// <param name="pDentistID">int</param>
    public string DeleteMyDentist(int pDentistID)
    {
        Manager objManager = new Manager(true,"ConnectionString");
        SqlParameter[] objSqlParameter = new SqlParameter[3];
        objSqlParameter[0] = new SqlParameter("@DentistID", SqlDbType.BigInt);
        objSqlParameter[0].Value = pDentistID;
        objSqlParameter[1]=new SqlParameter("@IsError",SqlDbType.Bit);
        objSqlParameter[1].Direction = ParameterDirection.Output;
        objSqlParameter[2] = new SqlParameter("UserID",SqlDbType.BigInt);
        objSqlParameter[2].Value = Convert.ToInt32(HttpContext.Current.Session["UserId"]);
        objManager.ExecuteQuery("DeleteMyDentist", objSqlParameter);
        if (Convert.ToBoolean(objSqlParameter[1].Value))
        {
            objManager = null;
            return "Dentist can not delete from my dentist list";
        }
        else
        {
            objManager = null;
            return "Dentist has been deleted from my dentist list";
        }
    }

    /// <summary>
    /// public static bool IsFeatureDentist(int DentistID)
    /// This function is use for check Dentist is feature Dentist or not
    /// </summary>
    /// <author>Vinayak Singh Rathore</author>
    /// <date>6 Oct, 2007</date>
    /// <param name="DentistID">int</param>
    /// <returns>bool</returns>
    public static bool IsFeatureDentist(int DentistID)
    {
        Manager objManager = new Manager(true,"ConnectionString");
        SqlParameter[] objSqlParameter = new SqlParameter[2];
        objSqlParameter[0] = new SqlParameter("@DentistID", SqlDbType.BigInt);
        objSqlParameter[0].Value = DentistID;
        objSqlParameter[1] = new SqlParameter("@IsDentist", SqlDbType.Bit);
        objSqlParameter[1].Direction = ParameterDirection.Output;
        objManager.ExecuteQuery("DentistIsFeaturDentist", objSqlParameter);
        objManager = null;
        return Convert.ToBoolean(objSqlParameter[1].Value);
    }
}
